/**
 * Project: topdt-jbpm
 * Copyright 2013  Top Digital Technology  Co. Ltd.
 * All right reserved.
 */
package com.topdt.jbpm.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.thx.common.orm.HibernateBaseDao;
import com.thx.common.util.AppContext;
import com.topdt.jbpm.model.Control;

/**
 * 建立日期 : 2013-4-25 下午12:03:29<br>
 * 作者 : balance<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
@Repository
public class ControlDao extends HibernateBaseDao<Control>{


	public Control getControlByObjects(String appId,String flowId,String activity,String formId) {
		String comId = AppContext.getCurrentComId();
		String condition = "";
		if (comId != null && !"".equals(comId))
			condition = "companyId='" + comId + "' and ";
		String hql = "from Control where "+condition+"appId =? and flowId=? and activityName =? and formId =?";
        List<Control> list = createQuery(hql, appId,flowId,activity,formId).list();
		if (list!=null&&list.size() > 0)
			return (Control) list.get(0);
		return null;
	}

    @SuppressWarnings("unchecked")
	public Control getControlByObjects(Object[] objs) {
		String comId = AppContext.getCurrentComId();
		String condition = "";
		if (comId != null && !"".equals(comId))
			condition = "companyId='" + comId + "' and ";
		String hql = "from Control where "+condition+"appId =? and flowId=? and activityName =? and formId =?";
        List<Control> list = createQuery(hql, objs).list();
		if (list!=null&&list.size() > 0)
			return (Control) list.get(0);
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Control> findControlByObjects(Object[] objs) {
		String comId = AppContext.getCurrentComId();
		String condition = "";
		if (comId != null && !"".equals(comId))
			condition = "companyId='" + comId + "' and ";
		String hql = "from Control where  "+condition+"appId =? and flowId =? and formId =?";
		List<Control> list = createQuery(hql, objs).list();
		if (list!=null&&list.size() > 0)
			return list;
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Control> findContrlsByFlowIdAndAppId(String flowId,String appId){
		String comId = AppContext.getCurrentComId();
		String condition = "";
		if (comId != null && !"".equals(comId))
			condition = "companyId='" + comId + "' and ";
		String hql = "from Control where "+condition+"flowId =? and appId=?";
		List<Control> list = createQuery(hql, flowId,appId).list();
		if (list!=null&&list.size() > 0)
			return list;
		return null;
	}
}
